<template>
  <div id="zhidu">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item><b>制度检索</b></el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
        <el-form :inline="true" :model="filters">
          <div>
            <el-form-item label="年 度">
              <el-select v-model="filters.Theyear" placeholder="请选择">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in yearoptions" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="文 件">
              <el-input v-model="filters.Name" placeholder="文件标题关键词" @keyup.enter.native="searchZhidu"></el-input>
            </el-form-item>
            <el-form-item label="发文机关">
              <el-input v-model="filters.Fawenjiguan" placeholder="发文机关关键词" @keyup.enter.native="searchZhidu"></el-input>
            </el-form-item>
            <el-form-item label="字 号">
              <el-input v-model="filters.Zihao" placeholder="字号" @keyup.enter.native="searchZhidu"></el-input>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="分类1">
              <el-select v-model="filters.Fenleione">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in class1options" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="分类2">
              <el-select v-model="filters.Fenleitwo">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in class2options" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否执行">
              <el-select v-model="filters.Shifouzhixing">
                <el-option v-for="item in zhixingoptions" :key="item.index" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchZhidu" icon="el-icon-search">查询</el-button>
            </el-form-item>
            <el-form-item v-if="inRoles('ROLE_admin')||inRoles('ROLE_zhidudata')">
              <el-button type="success" @click="importZhidu" icon="el-icon-setting"  circle></el-button>
            </el-form-item>
          </div>
        </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <h1>制度检索结果</h1>
      <el-table :data="docs" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border>
        <el-table-column type="index" label=" " width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="theyear" label="年度" width="100">
        </el-table-column>
        <el-table-column prop="name" label="文件" min-width="250">
        </el-table-column>
        <el-table-column prop="fawenjiguan" label="发文机关" width="200">
        </el-table-column>
        <el-table-column prop="zihao" label="字号" width="180">
        </el-table-column>
        <el-table-column prop="fenleione" label="分类1" width="180">
        </el-table-column>
        <el-table-column prop="fenleitwo" label="分类2" width="180">
        </el-table-column>
        <el-table-column label="是否执行" width="100">
          <template slot-scope="scope">
            {{tf2sf(scope.row.shifouzhixing)}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button size="small" @click="docdownload(scope.row.id)" type="text" icon="el-icon-download">下载</el-button>
          </template>
        </el-table-column>
      </el-table>
    <div class="block">
      <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div>
    </section>
  </div>
</template>

<script>
import getunits from '@/js/common.js'
export default {
  data () {
    return {
      filters: {
        Title: '',
        Dept: '',
        Num: '',
        Year: '',
        Class1: '',
        Class2: '',
        Zhixing: ''
      },
      discs: {},
      yearoptions: [],
      class1options: [],
      class2options: [],
      zhixingoptions: [{
        label: '全部',
        value: ''
      }, {
        label: '是',
        value: true
      }, {
        label: '否',
        value: false
      }],
      roleoptions: [],
      deptoptions: [],
      docs: [],
      total: 0,
      pageNum: 1,
      pageSize: 20,
      listLoading: false,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      changeSizeFlag: false,
      tableHeight: 100
    }
  },
  methods: {
    inRoles (str) {
      let arr = JSON.parse(localStorage.getItem('Roles'))
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    tf2sf (tf) {
      if (tf) {
        return '是'
      } else {
        return '否'
      }
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getZhidu()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getZhidu()
      }
    },
    querySearch (queryString, cb) {
      return getunits(this, queryString, cb)
    },
    // 查询
    searchZhidu () {
      this.pageNum = 1
      this.getZhidu()
    },
    // 维护
    importZhidu () {
      this.$router.push({ name: 'ZhiduImport' })
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = true
      } else {
        this.Isace = false
      }
      this.getUsers()
    },
    getZhidu () {
      let para = {
        Theyear: this.filters.Theyear,
        Name: this.filters.Name,
        Shifouzhixing: this.filters.Shifouzhixing,
        Fenleione: this.filters.Fenleione,
        Fenleitwo: this.filters.Fenleitwo,
        Fawenjiguan: this.filters.Fawenjiguan,
        Zihao: this.filters.Zihao,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      var _this = this
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(`/ps/search`, para)
        .then(function (response) {
          _this.listLoading = false
          _this.docs = response.data.list
          _this.totalnum = response.data.total
          _this.changeSizeFlag = false
        })
        .catch(function (error) {
          _this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getDics () {
      var _this = this
      this.$http
        .get(`/ps/dic`)
        .then(function (response) {
          _this.yearoptions = response.data.dicyear
          _this.class1options = response.data.dicfenlei1
          _this.class2options = response.data.dicfenlei2
        })
        .catch(function (error) {
          _this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 323
      })
    },
    docdownload (id) {
      window.open(this.$http.defaults.baseURL + 'ps/file/' + id)
    }
  },
  mounted () {
    this.getZhidu()
    this.getDics()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #zhidu .el-form-item{
    font-size:var(--size14) !important;
    font-family: '宋体';
    margin:0 10px 0 0;
  }
  #zhidu .el-form-item__label{
    font-size:var(--size14) !important;
    font-family: '宋体'
  }
  #zhidu .el-input__inner{
    font-size:var(--size14) !important;
    line-height: 20px;
    height:30px;
    padding: 5px;
    border-radius: 0;
  }
  #zhidu .el-button{
    padding: 7px;
    border-radius: 0;
  }
</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
